package com.sxl.ocr.ocronnx.route;

import com.sxl.ocr.ocronnx.handler.OCRHandler;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.MediaType;
import org.springframework.web.reactive.function.server.RouterFunction;
import org.springframework.web.reactive.function.server.RouterFunctions;
import org.springframework.web.reactive.function.server.ServerResponse;

import static org.springframework.web.reactive.function.server.RequestPredicates.*;

/**
 * description:
 * author: shenxiaolong
 * date: 2021/1/27  16:55
 */
@Configuration
public class RoutingConfiguration {

    @Bean
    public RouterFunction<ServerResponse> monoRouterFunction(OCRHandler ocrHandler) {
        return RouterFunctions
                .route(POST("/ocr/onnx").and(accept(MediaType.MULTIPART_FORM_DATA)),  ocrHandler::getOnnxOcrResult)
                .andRoute(GET("/ocr/health").and(accept(MediaType.APPLICATION_JSON)), ocrHandler::testHealth);

    }
}
